package common.coucurrency;

import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

/**
 * Created by Gerardo on 1/26/14.
 */
public class Person extends Thread {
	private final Semaphore machines;

	public Person(final Semaphore machines, final String name) {
		this.machines = machines;
		this.setName(name);
		this.start();
	}

	@Override
	public void run() {
		try {
			System.out.println(getName() + " Waiting ATM");
			machines.acquire();
			System.out.println(getName() + " Using ATM");
			Thread.sleep(TimeUnit.SECONDS.toMillis(10));
			System.out.println(getName() + " Releasing ATM");
			machines.release();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
